
/*
* GetCount 获取编辑器字数
* */
import {DomEditor, IDomEditor} from "@wangeditor/editor";

export function GetCount<T extends IDomEditor>(editor:T): number {
    let text = editor.getText()
    if (text === undefined || text === '') {
        return 0
    }
    return text.length
}

/*
* GetSelectCount 获取编辑器鼠标选中字数
* */
export function GetSelectCount<T extends IDomEditor>(editor:T):number {
    let select = editor.getSelectionText()
    if (select === undefined) {
        return 0
    }
    return select.length
}

export function GetLineNumber<T extends IDomEditor>(editor:T):number {
    let html = editor.getHtml();

    return 0
}
/*
*   编辑器当前行高亮
* */
export function LineHeight<T extends IDomEditor>(editor: T) {

    // const { $textArea } = DomEditor.getTextarea(editor)
    // if ($textArea == null) return
    //
    // console.log($textArea)


    // 获取编辑器
    let selection = window.getSelection();
    if (selection!==null){
        let rangeAt = selection.getRangeAt(0);
        let select = editor.selection;
        // 获取光标 位置的html元素
        let focusElement = selection.anchorNode!.parentNode!.parentNode!.parentElement

        console.log(focusElement!.id)
        let id =focusElement!.id
        if (id===''){
            return
        }
        let elementById = document.getElementById(id);
        if (elementById===null){
            return;
        }
        let name=elementById.tagName
        console.log("line element name:",name)
        if (name!=='P'){
            return;
        }
        elementById.style.backgroundColor='#FCFAEDFF'

        // let editableContainer = editor.getEditableContainer();
        // console.log(editableContainer)
        // let selectionPosition = editor.getSelectionPosition();
        // console.log(selectionPosition)
        // let clientRect = editableContainer.getBoundingClientRect();
        // console.log(clientRect)
    }

}